package com.jason.www.service;


import com.jason.www.code.IPayClient;
import com.jason.www.code.PayClientFactory;
import com.jason.www.enums.PayType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by Liguoxing on 2018/11/29.
 */
@Service
@Slf4j
public class PayServiceImpl implements IPayService {


    @Autowired
    private PayClientFactory payClientFactory;

    @Override
    public String constructPayMessage(PayType payType, Map<String, String> params) {
        IPayClient payClient = payClientFactory.getPayClient(payType);
        return payClient.buildRequestUrl(params);
    }

    @Override
    public String constructPayMessage(Byte payType, Map<String, String> params) {
        IPayClient payClient = payClientFactory.getPayClient(payType);
        return payClient.buildRequestUrl(params);
    }

    @Override
    public Boolean verifyCallbackHmac(Byte payType, Map<String, String> rspData) {
        IPayClient payClient = payClientFactory.getPayClient(payType);
        return payClient.verifyCallbackHmac(rspData);
    }

	@Override
	public String pay(Byte payType, Map<String, String> params) {
		//通过code
		return constructPayMessage(payType,params);
		//通过枚举
		//return constructPayMessage(payTypeEnum,params);
	}

	@Override
    public Boolean verifyCallbackHmac(PayType payType,Map<String, String> rspData) {
        IPayClient payClient = payClientFactory.getPayClient(payType);
        return payClient.verifyCallbackHmac(rspData);
    }
}
